package com.desksoft.ecommerce.util.html.element;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

/***************************************
 * 版权所有：杭州迪科软件 保留所有权利
 * 创建日期: 
 * 创建作者：luoy
 * 文件名称：页面元素父类
 * 版本：
 * 功能：
 * 最后修改时间：
 * 修改记录：
 *****************************************/
public class PageElement implements Serializable {

	protected String target;		//	页面标签
	
	protected String id;			//	页面标签ID属性
	protected String cssClass;			//	class属性值
	
	protected String text;
	
	protected PageElement parent;			//	父元素
	protected List<PageElement> children;	//	第一层子元素集合
	
	protected String style;
	
	public PageElement() {
		super();
		children = new ArrayList<PageElement>();
	}
	
	public String toHtml(){
		
		StringBuffer html = new StringBuffer();
		if (this.getTarget()!=null){
			html.append("<"+this.getTarget()+" id='" + this.id + "'  class='"+this.getCssClass()+"' style='" + this.style + "' >");
		}
		if (this.text!=null){
			html.append(" "+text+" ");
		}
		for (PageElement child : this.children){
			html.append("\n"+child.toHtml()+"\n");
		}
		if (this.getTarget()!=null){
			html.append("</"+this.getTarget()+">");
		}
		return html.toString();
	}
	
	public PageElement(Element element){
		this.target = element.attributeValue("target");
		this.id = element.attributeValue("id");
		this.cssClass = element.attributeValue("cssClass");
		this.style = element.attributeValue("style");
		Element textElmt = element.element("text");
		if (textElmt!=null&&textElmt.getText()!=null){
			this.text = textElmt.getText();
		}
	}
	
	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public String getCssClass() {
		return cssClass;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	public PageElement getParent() {
		return parent;
	}

	public void setParent(PageElement parent) {
		this.parent = parent;
	}

	public List<PageElement> getChildren() {
		return children;
	}

	public void setChildren(List<PageElement> children) {
		this.children = children;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	
}
